package com.cooper.slidingmenu.utils;

import com.cooper.slidingmenu.utils.ConfirmDialog.ConfirmDialogListener;
import com.cooper.slidingmenu.utils.FullWatiDialog.FullWatiDialogListener;
import com.cooper.slidingmenu.utils.SampleInputDialog.SampleInputDialogListener;
import com.cooper.slidingmenu.utils.SampleItemSelectDialog.SampleItemSelectDialogListener;

import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.util.Log;

public abstract class SampleDialogBaseFragment extends Fragment implements
		SampleItemSelectDialogListener, SampleInputDialogListener,
		ConfirmDialogListener, FullWatiDialogListener {

	public SampleDialogBaseFragment() {
		super();
	}

	@Override
	public void onConfirmDialogReturn(int which, boolean isOk) {

	}

	@Override
	public void onSampleInputDialogReturn(int which, boolean isOk, String text) {
	}

	@Override
	public void onSampleItemsSelectDialogReturn(int which, int selectWhich) {

	}

	protected void showConfirmDialog(int which, String title, String msg) {
		ConfirmDialog.newInstance(which, title, msg).show(
				getActivity().getSupportFragmentManager(), "CONFIRM_DIALOG");
	}

	protected void showConfirmDialog(int which, int titleRes, String msg) {
		ConfirmDialog.newInstance(which, getResources().getString(titleRes),
				msg).show(getActivity().getSupportFragmentManager(),
				"CONFIRM_DIALOG");
	}

	protected void showConfirmDialog(int which, int titleRes, int msgRes) {
		ConfirmDialog.newInstance(which, getResources().getString(titleRes),
				getResources().getString(msgRes)).show(
				getActivity().getSupportFragmentManager(), "CONFIRM_DIALOG");
	}

	protected void showSampleInputDialog(int which, String title,
			String initText) {
		SampleInputDialog.newInstance(which, title, initText).show(
				getActivity().getSupportFragmentManager(),
				"SAMPLE_INPUT_DIALOG");
	}

	protected void showSampleInputDialog(int which, int title, String initText) {
		SampleInputDialog.newInstance(which, title, initText).show(
				getActivity().getSupportFragmentManager(),
				"SAMPLE_INPUT_DIALOG");
	}

	protected void showFullWaitingDialog(int msgRes, boolean cancelable) {
		FullWatiDialog.newInstance(msgRes, cancelable).show(
				getActivity().getSupportFragmentManager(),
				"FULL_WAITING_DIALOG");
	}

	protected void showFullWaitingDialog(String msgRes, boolean cancelable) {
		FullWatiDialog.newInstance(msgRes, cancelable).show(
				getActivity().getSupportFragmentManager(),
				"FULL_WAITING_DIALOG");
	}

	protected void dismissDialogByTag(String tag) {
		Fragment fragment = getActivity().getSupportFragmentManager()
				.findFragmentByTag(tag);
		if ((fragment != null) && (fragment instanceof DialogFragment)) {
			try{
			((DialogFragment) fragment).dismiss();
			}catch (Exception e){
				Log.e("SampleDialogBaseFragment",e.getMessage(),e);
			}
		}
	}

	protected void dismissFullWaitingDialog() {
		dismissDialogByTag("FULL_WAITING_DIALOG");
	}

}